<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	
<script type="text/javascript">
$(function() {

	   $('#hkl').blur(function(){
          var hkl=$(this).val(); 
          var sjxs=$('#sjxs').text();
          if(parseInt(sjxs)<parseInt(hkl)){
        	var dialog = art.dialog({title: '警告',icon:'question',lock: true});
      		dialog.content('<p>合格回库量不能大于实际销售量<p>');
            }else{
        	  $('#bfl').val(sjxs-hkl);
          }
		});

	   $('#bfl').blur(function(){
	          var bfl=$(this).val(); 
	          var hkl=$('#hkl').val(); 
	          var sjxs=$('#sjxs').text();
	          if(sjxs<(parseInt(hkl)+parseInt(bfl))){
	        	var dialog = art.dialog({title: '警告',icon:'question',lock: true});
	      		dialog.content('<p>合格回库量加上不合格报废量不能大于实际销售量<p>');
	            }
			});
		   
	
    $('.save').click(function(){
    	 var tds=$(this).parent().siblings();
    	 var orderid=tds.eq(0).text();
    	 var opid=tds.eq(2).text();
    	 var status=tds.eq(3).text();
    	 var sku=tds.eq(4).text();
    	 var hkl=tds.eq(9).find('input').val();
    	 var bfl=tds.eq(10).find('input').val();
    	 var remark=tds.eq(11).find('input').val();
         if(status=='未出库'){
        	 var dialog = art.dialog({title: '警告',icon:'question',lock: true});
        		dialog.content('<p>该订单为已发货但系统未作出库记录的订单，无法重新入库<p>');
        		return;
         }
    	 $.get(
    			 '<?php echo URL::base() ?>warehouse/tuijian_insert',
    	    	    {
    				    orderid: orderid,
    				    opid:opid,
    				    sku: sku,
    				    hkl: hkl,
    				    bfl: bfl,
    				    remark:remark,
    		    	 },
    		    	  function(data){alert(data);
    		    		 var dialog = art.dialog({title: '提示',icon:'question',lock: true,time: 0.5});
    		        	 dialog.content(data);
												if(data=='保存成功'){
                         setTimeout("window.location.href='<?php echo URL::base() ?>warehouse/select_tuijian'",500);
												}
    		   	   }
    	    	 );
        });
	//上传表格
    $(".upSuppForm").Validform({
        tiptype:2,});
     });
</script>
<style>
.myborder , .myborder th , .myborder td{border: 1px solid #bbb;}
</style>
<div class="row">
<div class="span11">
<h2>单个订单退件扫描入库：</h2>
<form method='GET' action='<?php echo URL::site() ?>warehouse/select_tuijian'>
请输入erp订单号：<input type='text' id='erp_order_id' name='erp_order_id'> &nbsp;&nbsp;<input type='submit' value='查询' class="btn btn-primary "></form>
<table  class="table table-bordered myborder">
<tr>
<th>erp订单号</th>
<th>平台单号</th>
<th>订单物品号</th>
<th>物品出库状态</th>
<th>sku</th>
<th>sku名称</th>
<th>储位</th>
<th>销售单价</th>
<th>实际销售量</th>
<th>合格回库量</th>
<th>不合格报废量</th>
<th>备注</th>
<th>操作</th>
</tr>
<?php foreach ($results as $result):?>
<tr>
<td><?php echo $result['erp_orders_id']?></td>
<td><?php echo $result['ebay_orders_id']?$result['ebay_orders_id']:'暂无' ?></td>
<td><?php echo $result['orders_products_id']?></td>
<td><?php echo $result['status']?></td>
<td><?php echo $result['orders_sku']?></td>
<td><?php echo $result['products_name_cn']?></td>
<td><?php echo $result['products_place']?></td>
<td><?php echo $result['item_price']?></td>
<td id='sjxs'><?php echo $result['item_count']?></td>
<td><input id="hkl" class="input-mini" type="text" value=0 onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
<td><input id="bfl" class="input-mini" type="text" value=0 onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
<td><input class="input-mini" type="text"></td>
<td><input type="button" class='btn btn-success save' value="保存"></td>
</tr>
<?php endforeach;?>
</table>
</div>


  <div class="span11"><hr/>
  <h2>订单退件批量上传数据入库：</h2>
  <form class="upSuppForm" method='post' action='<?php echo URL::site() ?>warehouse/upload_warehouse' enctype="multipart/form-data">
  <table class="table ">
     <tr>
       <td class="need"></td>
                    <td>批量上传</td>
                    <td> <input type='file' style="line-height: 0px;" name='xls' class="inputxt" datatype="/.+\.xls/"  nullmsg="请选择上传文件"  errormsg="文件格式只能为xls"/></td>
                    <td><div class="Validform_checktip"></div></td>
      </tr>
      <tr>
	       <td class="need"></td>
	       <td></td>
	       <td colspan="2">
	       
	       </td>
      </tr>
     </table>
      <input type='submit' value='上传' class='btn btn-success' />
    <div class="btn btn-info" style='margin-left:50%'><a href="<?php echo URL::site() ?>warehouse/default_down" style="color: #ffffff">下载模版<a/></div>
  </form> 
  </div>
</div>
